<?php
class SideboxesController extends AppController {

	var $name = 'Sideboxes';

	function admin_index() {
		$this->Sidebox->recursive = 0;
		$this->set('sideboxes', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$this -> Sidebox -> findById($id)) {
			$this->Session->setFlash(__('SIDEBOX_INVALID',true));
			$this->redirect(array('action'=>'index'), null, true);
		}
		$this->set('sidebox', $this->Sidebox->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Sidebox->create();
			if ($this->Sidebox->save($this->data)) {
				$this->Session->setFlash(__('SIDEBOX_SAVED_OK',true));
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash(__('SIDEBOX_SAVED_ERROR',true));
			}
		}
	}

	function admin_edit($id = null) {
		if (!$this -> Sidebox -> findById($id)) {
			$this->Session->setFlash(__('SIDEBOX_INVALID',true));
			$this->redirect(array('action'=>'index'), null, true);
		}
		if (!empty($this->data)) {
			$this->cleanUpFields();
			if ($this->Sidebox->save($this->data)) {
				$this->Session->setFlash(__('SIDEBOX_SAVED_OK',true));
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash(__('SIDEBOX_SAVED_ERROR',true));
			}
		} else {
			$this->data = $this->Sidebox->read(null, $id);
		}
	}

	function admin_delete($id = null) {
		if (!$this -> Sidebox -> findById($id)) {
			$this->Session->setFlash(__('SIDEBOX_INVALID',true));
		}
		if ($this->Sidebox->del($id)) {
			$this->Session->setFlash(__('SIDEBOX_DELETED_OK',true));
		}
		$this->redirect(array('action'=>'index'), null, true);
	}

	function admin_delete_sideboxes() {
		if($this -> Sidebox -> deleteAll(array('Sidebox.id'=>$this -> data['SideboxesDelete']))) {
			$this->Session->setFlash(__('SIDEBOXES_DELETED_OK',true));
		} else {
			$this->Session->setFlash(__('SIDEBOXES_DELETED_ERROR',true));
		}
		$this->redirect(array('action'=>'index'), null, true);
	}
}
?>